package com.xxdd.kotlindemo

import android.content.Intent
import android.os.Bundle
import android.view.MotionEvent
import android.widget.TextView
import com.xxdd.lifecyclelib.LifecycleInterface

class ContainerAcitivity : BaseActivity(){
    lateinit var lifecycleInterface: LifecycleInterface



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

//        var className = intent.getStringExtra("className")


//        val clazz =  getClassLoader().loadClass("com.xxdd.plugina.MainActivity")
        var className = intent.getStringExtra("className")
        val clazz =  getClassLoader().loadClass(className ?: "com.xxdd.plugina.MainActivity")
        lifecycleInterface = clazz.newInstance() as LifecycleInterface
        lifecycleInterface.attach(this)

        lifecycleInterface.onCreate(savedInstanceState)
//        lifecycleInterface.
    }



    override fun onStart() {
        super.onStart()
        lifecycleInterface.onStart()
    }

    override fun onResume() {
        super.onResume()
        lifecycleInterface.onResume()
    }

    override fun onStop() {
        super.onStop()
        lifecycleInterface.onStop()
    }

    override fun onDestroy() {
        super.onDestroy()
        lifecycleInterface.onDestroy()
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        lifecycleInterface.onSaveInstanceState(outState)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        lifecycleInterface.onTouchEvent(event)
        return super.onTouchEvent(event)

    }

    override fun onBackPressed() {
        super.onBackPressed()
        lifecycleInterface.onBackPressed()
    }

//    open fun onCreate(savedInstanceState : Bundle?)
//    open fun onStart()
//    open fun onResume()
//    open fun onStop()
//    open fun onDestroy()
//    open fun onSaveInstanceState(outState : Bundle?)
//    open fun onTouchEvent(event : MotionEvent)
//    open fun onBackPressed()





}